package com.kbbywyclient.util;

import android.content.Context;

import com.kbbywyclient.widget.PicassoImageLoader;

import cn.finalteam.galleryfinal.CoreConfig;
import cn.finalteam.galleryfinal.FunctionConfig;
import cn.finalteam.galleryfinal.GalleryFinal;
import cn.finalteam.galleryfinal.ThemeConfig;

/**
 * Description:
 * Created by FHW
 * on 2017/5/4
 */

public class GalleryFinalUtil {


    public static final int REQUEST_CODE_GALLERY = 101;//相册
    public static final int REQUEST_CODE_CAMERA = 102;//拍照
    public static final int REQUEST_CODE_CROP = 103;//裁剪
    public static final int REQUEST_CODE_EDIT = 103;//编辑

    private static FunctionConfig functionConfig;

    public static void init(Context context) {
        //设置主题
//ThemeConfig.CYAN
        ThemeConfig theme = new ThemeConfig.Builder()
                .build();
        //配置功能
        functionConfig = new FunctionConfig.Builder()
//                .setEnableCamera(true)
                .setEnableEdit(true)
                .setEnableCrop(true)
                .setEnableRotate(true)
                .setCropSquare(true)
//                .setEnablePreview(true)
                .build();

//配置imageloader
        PicassoImageLoader imageloader = new PicassoImageLoader();
        CoreConfig coreConfig = new CoreConfig.Builder(context, imageloader, theme)
//                .setDebug(BuildConfig.LOG_DEBUG)
                .setFunctionConfig(functionConfig)
                .build();
        GalleryFinal.init(coreConfig);
    }

    //单选打开相册
    public static void openGallerySingle(GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback) {
        //带配置
        GalleryFinal.openGallerySingle(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
    }

    //多选打开相册
    public static void openGalleryMuti(int maxNum, GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback) {
        functionConfig = new FunctionConfig.Builder()
                .setMutiSelectMaxSize(maxNum)
                .build();
        GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
    }

    //使用拍照
    public static void openCamera(GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback) {
        //带配置
        GalleryFinal.openCamera(REQUEST_CODE_CAMERA, functionConfig, mOnHanlderResultCallback);
    }

    //使用裁剪
    public static void openCrop(String imgPath, GalleryFinal.OnHanlderResultCallback mOnHanlderResultCallback) {
        //带配置
        GalleryFinal.openCrop(REQUEST_CODE_CROP, functionConfig, imgPath, mOnHanlderResultCallback);
    }

}
